package com.android.benbourahla.carmode;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

import com.android.benbourahla.carmode.utils.SMSUtils;
import com.android.benbourahla.carmode.utils.Utils;

public class CarModeHomeActivity extends Activity
{
	private ImageButton	carMode					= null;
	private Drawable		carModeDrawable	= null;
	private Boolean			isClicked 			= false;
	private SharedPreferences shared 		= null;
	private Editor						editor		= null;
	

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		shared = getSharedPreferences(Utils.sharedName, 0);
		editor = shared.edit();
		
		carMode = (ImageButton) findViewById(R.id.CarHome);
		carMode.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View arg0)
			{
				if (true == isClicked)
				{
					carModeDrawable = getResources().getDrawable(R.drawable.button);
					isClicked = false;
					editor.putBoolean("IS_APP_ACTIVATED", isClicked);
					editor.commit();
					//SMSUtils.IS_APP_ACTIVATE = false;
					Intent serviceIntent = new Intent();
					serviceIntent.setAction("com.benbourahla.service.SMSService");
					stopService(serviceIntent);
				}
				else
				{
					carModeDrawable = getResources().getDrawable(
							R.drawable.pressed_button);
					isClicked = true;
					editor.putBoolean("IS_APP_ACTIVATED", isClicked);
					editor.commit();			
					//SMSUtils.IS_APP_ACTIVATE = true;
					Intent serviceIntent = new Intent();
					serviceIntent.setAction("com.benbourahla.service.SMSService");
					startService(serviceIntent);
					
				}
				Log.i("CarModeHomeScreen", Boolean.toString(SMSUtils.IS_APP_ACTIVATE));
				carMode.setBackgroundDrawable(carModeDrawable);
			}
		});
		
	}
	
	@Override
	protected void onDestroy()
	{
		editor.putBoolean("IS_APP_ACTIVATED", isClicked);
		editor.commit();
		super.onDestroy();
	}
	
	
}
